#!/usr/bin/perl
#use strict;
#use warnings;

#==================================================================================
#
# PROGRAM: Gb tool analyser
# Author: Tung Nguyen - Minh Truong.
# Co. Aricent Group
# Version: v10
#
#==================================================================================

#Reading input file and Open a new file for output:
#==================================================================================

if ($#ARGV + 1 != 1)
{
print "Gb tool analyser. \n";
#print "Usage: gb.plx file_input NSEI file_output\n";
print "Usage: gb.plx file_input file_output\n";
exit;
}

$file_input = <$ARGV[0]>;
#$NSEI = <$ARGV[1]>;
#$file_output = <$ARGV[2]>;

open INPUT, "<", $file_input or die $!;
#open $fin, "<", "log.txt" or die $!;

#$line_number = 0;
#$line = 1;
@array;
@array = <INPUT>;
#Create a directory to store the output files:
mkdir (output);

print "==============================\n";
print "Folder: Output\n";
print "File input: $file_input \n";
print "NSEI: $NSEI \n"; 
print "File output: $file_output \n"; 
print "==============================\n";
	
close ($fin);
#End of reading input file:=========================================================

#Write a some information for output file:
#print "Enter the NSEI: ", "\n";
#$NSEI = <$ARGV[1]>;
#chomp ($NSEI);

#======================================================================================================================
#Array use to store NSEs
@string_nsei;
@array_nsei;

for ($j = 0; $j < scalar(@array); $j++)
{
	chomp (@array[$j]);
	if (@array[$j] =~ /NSEI/ and @array[$j+1] =~ /-----------/)
	{
		@string_nsei = split /\s+/,@array[$j+2];

		for ($k = 0; $k < scalar(@string_nsei); $k++)
		{
			push (@array_nsei,@string_nsei[$k]);		
		}
	}
}
@unique = do { %seen; grep {!$seen{$_}++ } @array_nsei};

#for ($j = 0; $j < scalar(@array_nsei); $j++)
#{
#	for($k = $j + 1; $k <= scalar(@array_nsei); $k++)
#	{
#		if (@array_nsei[$j] == @array_nsei[$k])
#		{
#			@array_nsei[$k] = 65536;
#		}
#	}
#}

#for ($j = 0; $j < scalar(@unique); $j++)
#{
#	print @unique[$j],"\n";
#}

for ($j = 0; $j < scalar(@unique); $j++)
{
	$NSEI = sprintf("%x",@unique[$j]);
	print $NSEI,"\n";
	&get_all_alarm($NSEI);	
	&print_all_alarm($NSEI);	
}

#Procees the data:=====================================================================================================
#%alarm_hash;

#Array use to store collection of Gb alarms
sub get_all_alarm
{
@array_alarm;
 

for ($i = 0; $i < scalar(@array); $i++)	
{
	chomp (@array[$i]);

#Process alarm 3025---------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3025/ )
	{
#		print @array[$i-3], "\n";
		@string1 = split /\s+/,@array[$i-3];
#		$alarm_hash{type} = @string1[1];
#		$alarm_hash{exchange} = @string1[2];
#		$alarm_hash{computer} = @string1[3];
#		$alarm_hash{equipment} = @string1[4];
#		$alarm_hash{date} = @string1[5];
#		$alarm_hash{hour} = @string1[6];
		
#		print @array[$i-2], "\n";
		@string2 = split /\s+/,@array[$i-2];

#		$alarm_hash{urgency} = @string2[0];
#		$alarm_hash{printout} = @string2[1];
#		print $alarm_hash{printout}, "\n";
#		$alarm_hash{object} = @string2[2];
#		$alarm_hash{position} = @string2[3];
#		$alarm_hash{issuer} = @string2[4];

#		print @array[$i-1], "\n";
#		print $fout @array[$i-1], "\n";
		@string3 = split /\s+/,@array[$i-1];
		
#		$alarm_hash{consecutive_num} = @string3[1];
#		$alarm_hash{alarm_number} = @string3[2];
#		$alarm_hash{text} = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string[8].@string[9];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string[8].@string[9];

#		push @array_alarm, alarm_hash;		


#		print @array[$i], "\n";
#		print $fout @array[$i], "\n";
		@string4 = split /\s+/,@array[$i];

#		$alarm_hash{psei} = @string4[1];
#		$alarm_hash{nsei} = @string4[2];
#		$alarm_hash{pcu_id} = @string4[3];
#		$alarm_hash{nsvci} = @string4[4];
#		$alarm_hash{fr_bearer_ch} = @string4[5];
#		$alarm_hash{ip_adr} = hex(@string4[6]).".".hex(@string4[7]).".".hex(@string4[8]).".".hex(@string4[9]);
		$ip = hex(@string4[6]).".".hex(@string4[7]).".".hex(@string4[8]).".".hex(@string4[9]);
#		$alarm_hash{port} = hex(@string4[22]);
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => @string4[3], nsvci => hex(@string4[4]), fr_bearer_ch => @string4[5],
			ip_adr => $ip, port => hex(@string4[22]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4], consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => @string4[3], nsvci => hex(@string4[4]), fr_bearer_ch => @string4[5],
			ip_adr => $ip, port => hex(@string4[22]) });		
		}
		
	}

#Process alarm 3020--------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3020/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7];
		@string4 = split /\s+/,@array[$i];
#		$alarm_hash{erorr_status} = @string4[6];
		$ip = hex(@string4[7]).".".hex(@string4[8]).".".hex(@string4[9]).".".hex(@string4[10]);
#		$alarm_hash{port} = hex(@string4[23]);
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4], consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => @string4[3], nsvci => hex(@string4[4]), fr_bearer_ch => @string4[5],
			error_status => @string4[6], ip_adr => $ip, port => hex(@string4[23]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => @string4[3], nsvci => hex(@string4[4]), fr_bearer_ch => @string4[5],
			error_status => @string4[6], ip_adr => $ip, port => hex(@string4[23]) });		
		
		}
	}

#Process alarm 3019--------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3019/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6];
		@string4 = split /\s+/,@array[$i];
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => @string4[3]});		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4], consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => @string4[3]});		
		}
	}

#Process alarm 3030--------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3030/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string3[8];
		@string4 = split /\s+/,@array[$i];

		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), bcf => hex(@string4[3]), bts => hex(@string4[4]), bvci => hex(@string4[5])});	
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), bcf => hex(@string4[3]), bts => hex(@string4[4]), bvci => hex(@string4[5])});	
		}
	}

#Process alarm 3031--------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3031/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string3[8];
		@string4 = split /\s+/,@array[$i];
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), bcf => hex(@string4[3]), bts => hex(@string4[4]), bvci => hex(@string4[5]), 
			error_status => @string4[6] });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), bcf => hex(@string4[3]), bts => hex(@string4[4]), bvci => hex(@string4[5]), 
			error_status => @string4[6] });		
		}
	}

#Process alarm 3026-----------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3026/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string3[8];
		@string4 = split /\s+/,@array[$i];
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[4] });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[4] });		
		}
	}

#Process alarm 3032-------------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3032/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7];
		@string4 = split /\s+/,@array[$i];
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[3], bvci => hex(@string4[4]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[3], bvci => hex(@string4[4]) });		
		}
	}

#Process ZAHO command-------------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /ZAHO/ and (@array[$i+6] =~ /ALARMS CURRENTLY ON/))
	{
		@string1 = split /\s+/,@array[$i+4];
		push (@array_alarm, {type => "ZAHO", date => @string1[2], hour => @string1[3]});		
	}

#Process ZAHP command-------------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /ZAHP/ and (@array[$i+6] =~ /ALARM HISTORY/))
	{
		@string1 = split /\s+/,@array[$i+4];
		push (@array_alarm, {type => "ZAHP", date => @string1[2], hour => @string1[3]});		
	}

#Process alarm 3209------------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3209/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string3[8];
		@string4 = split /\s+/,@array[$i];
		$ip = hex(@string4[4]).".".hex(@string4[5]).".".hex(@string4[6]).".".hex(@string4[7]);
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[3], ip_adr => $ip, port => hex(@string4[20]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[3], ip_adr => $ip, port => hex(@string4[20]) });		
		}
	}

#Process alarm 3053------------------------------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-1] =~ /ALARM/ or @array[$i-1] =~ /CANCEL/) and @array[$i] =~ /3053/ )
	{
		@string1 = split /\s+/,@array[$i-2];
		@string2 = split /\s+/,@array[$i-1];
		@string3 = split /\s+/,@array[$i];
		$text_alarm = @string3[3].@string3[4].@string3[5];
		@string4 = split /\s+/,@array[$i+1];
		$ip = hex(@string4[4]).".".hex(@string4[5]).".".hex(@string4[6]).".".hex(@string4[7]);
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			usr_id => hex(@string4[1]), pci_bus => hex(@string4[2]), pci_dev_fn => @string4[3] });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			usr_id => hex(@string4[1]), pci_bus => hex(@string4[2]), pci_dev_fn => @string4[3] });		
		}
	}

#Process alarm 3210------------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3210/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string3[8];
		@string4 = split /\s+/,@array[$i];
		$ip = hex(@string4[4]).".".hex(@string4[5]).".".hex(@string4[6]).".".hex(@string4[7]);
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[3], ip_adr => $ip, port => hex(@string4[20]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), error_status => @string4[3], ip_adr => $ip, port => hex(@string4[20]) });		
		}
	}

#Process alarm 3322------------------------------------------------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3322/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string3[8].@string3[9];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			pcu_id => @string4[1], nsei => hex(@string4[2]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			pcu_id => @string4[1], nsei => hex(@string4[2]) });		
		}
	}

#Process alarm 3316------------------------------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3316/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), pcu_id => @string4[2], tlli => @string4[3], nri => hex(@string4[4]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), pcu_id => @string4[2], tlli => @string4[3], nri => hex(@string4[4]) });		
		}
	}

#Process alarm 3317------------------------------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3317/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), pcu_id => @string4[2] });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), pcu_id => @string4[2] });		
		}
	}

#Process alarm 3483------------------------------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3483/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			pcu_id => @string4[1], pcu => hex(@string4[2]), type_restart => @string4[3], cause  => hex(@string4[4]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			pcu_id => @string4[1], pcu => hex(@string4[2]), type_restart => @string4[3], cause  => hex(@string4[4]) });		
		}
	}

#Process alarm 1001-UNIT RESTART-----------------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /DISTUR/ ) and @array[$i-1] =~ /1001/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[0], alarm_number => @string3[1], text => $text_alarm, 
			cause => @string4[1] });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[0], alarm_number => @string3[1], text => $text_alarm, 
			cause => @string4[1] });		
		}
	}

#Process alarm 2115-----------------------------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /2115/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7].@string3[8];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			user_id => @string4[1], cause => hex(@string4[2]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			user_id => @string4[1], cause => hex(@string4[2]) });		
		}
	}

#Process alarm 3273-GPRS/EDGE TERITORY FAILED----------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3273/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string4[6], 
			position => @string2[3], issuer => @string2[3],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			bcf => hex(@string4[1]), bts => hex(@string4[2]), cell_area => @string4[3], trx_id => @string4[4], pcu_id => @string4[7], 
			cause => @string4[10] });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string4[6], 
			position => @string2[3], issuer => @string2[3],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			bcf => hex(@string4[1]), bts => hex(@string4[2]), cell_area => @string4[3], trx_id => @string4[4], pcu_id => @string4[7], 
			cause => @string4[10] });		
		}
	}

#Process alarm 0104-SGSN ENDPOINT CREATED--------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /NOTICE/ ) and @array[$i-1] =~ /0104/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[2].@string3[3].@string3[4];
		@string4 = split /\s+/,@array[$i];
		$ip = hex(@string4[3]).".".hex(@string4[4]).".".hex(@string4[5]).".".hex(@string4[6]);
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[0], alarm_number => @string3[1], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), ip_adr => $ip, port => hex(@string4[19]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[0], alarm_number => @string3[1], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), ip_adr => $ip, port => hex(@string4[19]) });		
		}
	}

#Process alarm 3115-ALL NSE UNVAILABLE ----------------------------------------------------------------------------------------------------------------------
	if ( (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3315/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), pcu_id => hex(@string4[2]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), pcu_id => hex(@string4[2]) });		
		}
	}

#Process alarm 3211-LAST REMOTE IP DATA ENDPOINT DELETED-----------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3211/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]) });		
		}
	}

#Process alarm 3482-SUB NETWORK SERVICE ADD PROCEDURE FAILED-------------------------------------------------------------------------------------------------
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) and @array[$i-1] =~ /3482/ )
	{
		@string1 = split /\s+/,@array[$i-3];
		@string2 = split /\s+/,@array[$i-2];
		@string3 = split /\s+/,@array[$i-1];
		$text_alarm = @string3[3].@string3[4].@string3[5].@string3[6].@string3[7];
		@string4 = split /\s+/,@array[$i];
		
		if(scalar(@string1)==7)
		{
			push (@array_alarm, {type => @string1[1], exchange => @string1[2], computer => @string1[3], equipment => @string1[4], 
			date => @string1[5], hour => @string1[6], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => hex(@string4[3]) });		
		}
		else
		{
			push (@array_alarm, {type => @string1[0], exchange => @string1[1], computer => @string1[2], equipment => @string1[3], 
			date => @string1[4], hour => @string1[5], urgency => @string2[0], printout => @string2[1], object => @string2[2], 
			position => @string2[3], issuer => @string2[4],	consecutive_num => @string3[1], alarm_number => @string3[2], text => $text_alarm, 
			psei => hex(@string4[1]), nsei => hex(@string4[2]), pcu_id => hex(@string4[3]) });		
		}
	}
}
}
#End of processing the data:====================================================================================================================================
#&get_all_alarm($NSEI);

#Write necessary information to the output file:================================================================================================================ 
sub print_all_alarm
{

#======================================================================================================================
#open $fout, ">", hex($NSEI).".txt";
$file_output = hex($NSEI).".txt";

open ($fout, ">./output/$file_output");

$time_string = localtime;
print $fout "NSEI: ", $NSEI," (",hex ($NSEI),"d)", " "x8,$time_string, "\n";
print $fout "\n";


printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		Type,P.out,Alarm,PSEI,NSEI,NSVC,BCSU,PCU,Date,Time,IP,Port,CAUSE,BCF,BVCI,PCU_ID,TLLI,NRI;
print $fout "-"x160, "\n";


for ($index = 0; $index < scalar (@array_alarm); $index++)
{

#Write alarm 3025 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3025)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},$array_alarm[$index]{nsvci},$array_alarm[$index]{object},$array_alarm[$index]{issuer},
		$array_alarm[$index]{date},$array_alarm[$index]{hour},$array_alarm[$index]{ip_adr},$array_alarm[$index]{port},"-"x4,"-"x5,"-"x5;
	}

#Write alarm 3020 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3020)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},$array_alarm[$index]{nsvci},$array_alarm[$index]{object},$array_alarm[$index]{issuer},
		$array_alarm[$index]{date},$array_alarm[$index]{hour},$array_alarm[$index]{ip_adr},$array_alarm[$index]{port},
		$array_alarm[$index]{error_status},"-"x5,"-"x5;
	}

#Write alarm 3019 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3019)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},
		$array_alarm[$index]{hour},"-"x15,"-"x5,"-"x4,"-"x5,"-"x5;
	}

#Write alarm 3030 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3030)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},
		$array_alarm[$index]{hour},"-"x15,"-"x5,"-"x4,$array_alarm[$index]{bcf},$array_alarm[$index]{bvci};
	}

#Write alarm 3031 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3031)
	{	
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		 "-"x15,"-"x5,$array_alarm[$index]{error_status},$array_alarm[$index]{bcf},$array_alarm[$index]{bvci};
	}

#Write alarm 3026 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3026)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,$array_alarm[$index]{error_status},"-"x5,"-"x5;
	}

#Write alarm 3032 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3032)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,$array_alarm[$index]{error_status},"-"x5,$array_alarm[$index]{bvci};
	}

#Write ZAHO command to the output file:------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{type} =~ /ZAHO/ )
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},"*"x6,"*"x4,"*"x2,"*"x5,"*"x5,"*"x7,"*"x9,$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"*"x15,"*"x5,"*"x5,"*"x5,"*"x5,"*"x6,"*"x8,"*"x4;
	}

#Write ZAHP command to the output file:------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{type} =~ /ZAHP/ )
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},"*"x6,"*"x4,"*"x2,"*"x5,"*"x5,"*"x7,"*"x9,$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"*"x15,"*"x5,"*"x5,"*"x5,"*"x5,"*"x6,"*"x8,"*"x4;
	}


#Write alarm 3209 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3209)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		$array_alarm[$index]{ip_adr},$array_alarm[$index]{port},$array_alarm[$index]{error_status},"-"x5,"-"x5;
	}
#Write alarm 3053 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3053)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x2,"-"x5,"-"x5,$array_alarm[$index]{object},
		$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},"-"x15,"-"x5,$array_alarm[$index]{usr_id},
		$array_alarm[$index]{pci_bus},$array_alarm[$index]{pci_dev_fn};
	}

#Write alarm 3210 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3210)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		$array_alarm[$index]{ip_adr},$array_alarm[$index]{port},$array_alarm[$index]{error_status},"-"x5,"-"x5;
	}

#Write alarm 3322 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3322)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x4,
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,"-"x4,"-"x5,"-"x5,$array_alarm[$index]{pcu_id};
	}

#Write alarm 3316 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3316)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x4,
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,"-"x4,"-"x5,"-"x5,$array_alarm[$index]{pcu_id},$array_alarm[$index]{tlli},$array_alarm[$index]{nri};
	}

#Write alarm 3317 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3317)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x4,
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,"-"x4,"-"x5,"-"x5,$array_alarm[$index]{pcu_id},"-"x8,"-"x4;
	}

#Write alarm 3483 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3483)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x4,
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,$array_alarm[$index]{cause},"-"x5,"-"x5,$array_alarm[$index]{pcu_id},"-"x8,"-"x4;
	}

#Write alarm 1001 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 1001)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x4,
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,$array_alarm[$index]{cause},"-"x5,"-"x5,"-"x6,"-"x8,"-"x4;
	}

#Write alarm 2115 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 2115)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x4,
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,$array_alarm[$index]{cause},"-"x5,"-"x5,"-"x6,"-"x8,"-"x4;
	}

#Write alarm 3273 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3273)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},"-"x4,
		"-"x5,"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,$array_alarm[$index]{cause},$array_alarm[$index]{bcf},"-"x5,$array_alarm[$index]{pcu_id},"-"x8,"-"x4;
	}

#Write alarm 0104 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} =~ /0104/)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		$array_alarm[$index]{ip_adr},$array_alarm[$index]{port},"-"x5,"-"x5,"-"x5,"-"x6,"-"x8,"-"x4;
	}

#Write alarm 3315 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3315)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		"-"x5,"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,"-"x4,"-"x5,"-"x5,$array_alarm[$index]{pcu_id},"-"x8,"-"x4;
	}

#Write alarm 3211 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3211)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,"-"x4,"-"x5,"-"x5,"-"x6,"-"x8,"-"x4;
	}

#Write alarm 3482 to the output file:-------------------------------------------------------------------------------------------------------------------------- 
	if ($array_alarm[$index]{alarm_number} == 3482)
	{ 
		printf $fout "%-6s  %-6s  %-4s  %-4s  %-5s  %-5s  %-7s  %-9s  %-10s  %-11s  %-15s  %-5s  %-5s  %-5s  %-5s  %-6s  %-8s  %-4s\n",
		$array_alarm[$index]{type},$array_alarm[$index]{printout},$array_alarm[$index]{alarm_number},$array_alarm[$index]{psei},
		$array_alarm[$index]{nsei},"-"x5,$array_alarm[$index]{object},$array_alarm[$index]{issuer},$array_alarm[$index]{date},$array_alarm[$index]{hour},
		"-"x15,"-"x5,"-"x4,"-"x5,"-"x5,$array_alarm[$index]{pcu_id},"-"x8,"-"x4;
	}
}
close ($fout);
}
#End of the writing output file:================================================================================================================================
#&print_all_alarm($NSEI);
